/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 9/25/12
 * Time: 10:42 PM
 * To change this template use File | Settings | File Templates.
 */
package vplib.maple {
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class MapleCodeAccess {
    private var fileName:String;
    private var dataFromFile:String;
    private var _eventDispatcher:EventDispatcher;

    public function MapleCodeAccess(file:String) {
        this.fileName = file;
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, onLoaded);
        loader.load(new URLRequest(this.fileName));
        trace("[PropertyAccess] - Loading data from file '" + this.fileName + "'.");
    }

    private function onLoaded(e:Event):void {
        this.dataFromFile = e.target.data;
        _eventDispatcher.dispatchEvent(new Event(Event.COMPLETE));
        trace("[PropertyAccess] - Load data from file '" + this.fileName + "'. \n\tData: " + e.target.data);
    }

    public function getValue(variableName:String):Object {
        var data:String = this.dataFromFile;
        var fPos:int = data.indexOf(variableName);
        data = data.substring(fPos);
        return null;
    }

    public function setValue(variableName:String, variableValue:Object):void {
        //
    }
}
}
